package com.zpark.config;

import com.zpark.Interceptor.LoginInterceptor;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

public class MyMvcConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        //创建拦截对象
        HandlerInterceptor interceptor=new LoginInterceptor();
        //注册拦截器
        InterceptorRegistration registration=registry.addInterceptor(interceptor);

        //配置拦截路径黑名单
        List<String> blackList=new ArrayList<>();
        blackList.add("/**");//拦截所有请求路径

        //配置不拦截的路径
        List<String> whiteList=new ArrayList<>();
        whiteList.add("/login.html");
        whiteList.add("/user/login.do");

        //添加拦截路径和不需要拦截的路径
        registration.addPathPatterns(blackList);
        registration.addPathPatterns(whiteList);
    }
}
